<?php

namespace app\common\model\order;

use app\common\model\BaseModel;

class HotelOrder extends BaseModel
{
    protected $name = 'hotel_order';
    protected $pk = 'id';

    protected $autoWriteTimestamp = 'int';
    protected $createTime = 'add_time';
    protected $updateTime = false;

    protected $type = [
        'add_time' => 'timestamp',
        'start_time' => 'timestamp',
        'end_time' => 'timestamp',
    ];
    
    /**
     * 字段验证规则
     * @var array
     */
    protected $schema = [
        'id'            => 'int',
        'user_id'       => 'int',
        'order_sn'      => 'string',
        'hotel_id'      => 'int',
        'room_id'       => 'int',
        'room_type_id'  => 'int',
        'status'        => 'int',
        'total_amount'  => 'float',
        'actual_amount' => 'float',
        'start_time'    => 'timestamp',
        'end_time'      => 'timestamp',
        'adult_num'     => 'int',
        'child_num'     => 'int',
        'contact_name'  => 'string',
        'contact_phone' => 'string',
        'guest_info'    => 'string',
        'add_time'      => 'timestamp',
        'remark'        => 'string',
    ];

    const STATUS_UN_PAID = 1;
    const STATUS_UN_DELIVERY = 2;
    const STATUS_DELIVERY = 3;
    const STATUS_UN_TAKE = 4;
    const STATUS_TAKE = 5;
    const STATUS_COMPLETE = 6;
    const STATUS_APPLY_REFUND = 7;
    const STATUS_REFUND = 8;

    /**
     * 多态关联 - 关联到订单表
     * @return \think\model\relation\MorphOne
     */
    public function order()
    {
        return $this->morphOne(Order::class, 'orderable', 'hotel');
    }
}